<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<#include "/common/plateform/include/common-base.ftl">
  <title>规则分类参数设置</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>

<!-- 以下是body主体内容的模块区域 -->
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

	<!-- top start -->
	<#include "/common/plateform/top.ftl">
	<!-- top end -->
	<!-- left start -->
	<#include "/common/plateform/left-project.ftl">
	<!-- left end-->

  <div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
      <div class="row">
        <div class="col-xs-12">
        
          <!------搜索  start ------->
          <div class="box box-info">
             <!--搜索title  start --> 
	          <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-search"></i> 规则分类搜索</h3>
                 <div class="box-tools pull-right">
	                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
	                </button>
	                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                 </div>
              </div>
            <!--搜索title  end -->

			  <div class="box-body">
				  <form id="searchForm" class="form-horizontal" action="javascript:;">
					  <input type="hidden" name="pageName" value="sys-cate"/>
					  <input type="hidden" name="formName" value="searchForm">
					  <input type="hidden" name="orderBy" value="sysCate.create_time desc"/>
					  <input type="hidden" name="sysCate.wi_sysName" id="search_sysName" value=""/>
					  <div class="form-group">
						  <div class="col-sm-2 text-right"><label class="control-label">分类编号：</label>
						  </div>
						  <div class="col-sm-3">
							  <input type="text" class="form-control clean"
									 name="sysCate.wl_cateNo" value=""/>
						  </div>
						  <div class="col-sm-2 text-right"><label class="control-label">分类名称：</label>
						  </div>
						  <div class="col-sm-3">
							  <input type="text" class="form-control clean"
									 name="sysCate.wl_cateName" value=""/>
						  </div>
					  </div>
					  <center>
						  <div class="box-footer clearfix">
							  <button type="button" class="btn btn-success"
									  onclick="getTableData();"><i
										  class="fa fa-search"></i> 查询
							  </button>&nbsp;
							  <button type="button" class="btn btn-warning"
									  onclick="mytools.cleanData('#searchForm');">重置
							  </button>
						  </div>
					  </center>
				  </form>
			  </div>

	     </div>
	     <!------- 搜索 end -------->
           
        <!------- 列表 start -------->
          <div class="box box-success">
            <!--列表title  start --> 
	          <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-table"></i> 规则分类参数设置列表 [<span id="span-sysname-text"></span>] [共计<span id="dataListTotalCount">0</span>条数据]
                 </h3>
                 <div class="box-tools pull-right">
	                 　　　　　　　　<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
	                </button>
	                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                 </div>
              </div>
            <!--列表title  end --> 
              <div class="box-body">
                <table id="dataList" class="table table-bordered table-hover" >
                <thead class="bg-success">
                <tr>
					<th style="width:20%">分类编号</th>
					<th style="width:30%">分类名称</th>
					<th>所属系统</th>
					<th>创建时间</th>
					<th>操作</th>
                </tr>
                </thead>
                <tbody id="dataList-body">
                </tbody>
              </table>
              <center>
    	  		<ul id="dataList-page"></ul>
              </center>
            </div>
           </div>
        <!------- 列表 end -------->
        </div>
      </div>
    </section>
    <!-- Main end -->
 <!-- 以下是template列表模板的模块区域 -->
<script type="text/template" id="dataList-template">
		<? for ( var i = 0; i < rows.length; i++) {?>
		<tr>
			<td><?=strUtil.doNull(rows[i].sysCate.cateNo,'')?></td>
			<td><?=strUtil.doNull(rows[i].sysCate.cateName,'')?></td>
			<td><?=strUtil.doNull(rows[i].sysCate.sysName,'')?></td>
			<td><?=strUtil.doNull(rows[i].sysCate.createTime,'')?></td>
              <td>
				  	<button type="button" class="btn btn-primary btn-xs" onclick="rulesTemplateManager('<?=rows[i].sysCate.cateId?>','<?=rows[i].sysCate.cateNo?>','<?=rows[i].sysCate.cateName?>');"><i class="fa fa-cog"></i> 参数设置</button>
				</td>
		</tr>
   <?}?>  		
</script>  
    
    
    
    
 <!-- 以下是js模块区域 -->
<script>
var clickMenu = "sysRulesProd-sets-list";
var id,myPage,dataListId,searchFormId,isShowLog,tableSort,tableId;
myPage = 10;
dataListId = "dataList";
searchFormId = "searchForm";
tableSort = "sysCate";
tableId = "cateId";
isShowLog = true;
var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
$("#span-sysname-text").text(defSysEname+"-"+strUtil.getLocalStorage("sysCname"));
$("#addForm").find("input[name='sysCate.sysName']").val(defSysEname);
$("#search_sysName").val(defSysEname);
$(function () {
	//1、加载分页列表数据
	getTableData();
	//2、控制是否启用token
	//setToken();
	
	//请在下面补充其他初始化方法（如数据字典、页面加载数据等）
	//3、初始化数据字典
 });
var dateObject = $('.datepicker').datepicker( {
	language : 'zh-CN',
	//inline: true,
	todayBtn : "linked",
	format : "yyyy-mm-dd",
	autoclose: true
});

//规则类型下规则项管理
function rulesTemplateManager(cateId,cateNo,cateName) {
	var url ="${page_admin}/project/sysRulesProd-sets?cateId="+cateId+"&cateNo="+cateNo+"&cateName="+cateName;
	mytools.pjax(url);
}

$(function () {
	$('#'+dataListId+' tbody').on('click','tr', function (e) {
		if ( $(this).hasClass('selected') ) {
	            //$(this).removeClass('selected');
	        }
	        else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     id = $('tr.selected td').eq(0).html();
	   //  console.log($('tr.selected td').eq(1).html())
	} );
	
	$("input[name='sysCate.cateNo']").change(function () {
		var cateNoVals = $(this).val();
		var form_id = $(this).parents("form").eq(0).attr("id");
		var this_cateId = "",thisInputId =$(this).attr("id");
		if(form_id){
			this_cateId=$("#"+form_id).find("input[name='sysCate.w_cateId']").val();
		}
		if(!strUtil.isNull(cateNoVals)){
			$.ajax({
				type:'get',
				url:common_list_url,
				data: {"pageName":"sys-cate","formName":"searchForm","sysCate.w_cateNo":cateNoVals},
				dataType:"json",
				success: function(myData){
					console.log('sysCate.check',myData);
					if(myData.total>0){
						var objData = myData.rows[0];
						var his_cateId = objData.cateId;
						console.log(this_cateId,his_cateId,thisInputId);
						if(!strUtil.isNull(this_cateId) && this_cateId==his_cateId){
							//修改时若是自己则认为不重复
							console.log('sysCate.check true');
						}else{
							console.log('sysCate.check false');
							layer.tips('此['+cateNoVals+']编号已存在，请更换！', '#'+thisInputId, {tips: 3});
							$('#'+thisInputId).val("");
							var fieldName ='sysCate.cateNo';//获取当前元素name
							$("#"+form_id).data('bootstrapValidator').updateStatus(fieldName,'NOT_VALIDATED',null).validateField(fieldName);
						}
					}
				}
			});
		}
	});
});
//加载列表数据
function getTableData(){
	deleteAllRow(dataListId);
	//搜索框去除空格
	$.ajax({
		   type:'get',
		   url:common_list_url,
		   data:$("#"+searchFormId).serialize()+getCurrentPage(common_list_url+"?"+$("#"+searchFormId).serialize(),myPage),
		   dataType:'json',
		   success: function(myData){
		   	console.log('sysCate',myData);
            $("#dataListTotalCount").text(myData.total);
			var data = baidu.template(dataListId+"-template",eval(myData));  
			$("#"+dataListId+"-body").html(data);
			  var option= {
					   ele:$("#"+dataListId+"-page")[0],
					   total:myData.total,
					   fn:getTableData,
					   url:common_list_url+"?"+$("#"+searchFormId).serialize()
				   }
				generatePages(option);
		   }
		});	
  }

//设置模态框隐藏事件 
//给模态窗口内form表单内的所有支持必填项的元素注入校验
$(".modal").on('shown.bs.modal', function () {
	$(this).find("form").each(function(){
		var formId = $(this).attr("id");
		if(!strUtil.isNull(formId)){
			formId="#"+formId;
			setValidate(formId);//定义add表单验证属性
			mytools.cleanValidate(formId);//清空上次校验规则提示
		}
	});
});
/**
 * 新增表单数据提交
 * @param formId
 */
function add(formId){
	//3.校验规则-表单提交时触发
	var validate = $('#'+formId).data('bootstrapValidator').validate();
	if(!validate.isValid()){ //如果校验不通过
	    return;  
	} 
	var index_submit = layer.confirm('您确定要提交信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
		$.ajax({
		    type:"post",
		    url:common_submit_url,
		    data:$("#"+formId).serialize(),
		    dataType:"json",
		    success: function(myData){
		    	//console.log(myData);
		    	if(myData.flag=="T"){
		    		layer.alert("数据保存成功");
		    		$("#my_modal_add").modal("hide");
		    	}else{
		    		layer.alert(myData.msg);
		    	}
		    	refresh();
		    	validata.resetForm();//清空校验规则
		  	}
		});	
	});
}

/**
 * 修改表单数据提交
 * @param formId
 */
function edit(formId){
	//3.校验规则-表单提交时触发
	var validate = $('#'+formId).data('bootstrapValidator').validate();
	if(!validate.isValid()){ //如果校验不通过
	    return;  
	} 
	var index_submit = layer.confirm('您确定要提交信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
		$.ajax({
		    type:"post",
		    url:common_submit_url,
		    data:$("#"+formId).serialize(),
		    dataType:"json",
		    success: function(myData){
		    	//console.log(myData);
		    	if(myData.flag=="T"){
		    		layer.alert("数据保存成功");
		    		$("#my_modal_edit").modal("hide");
		    	}else{
		    		layer.alert(myData.msg);
		    	}
		    	refresh();
		    	validata.resetForm();//清空校验规则
		  	}
		});	
	});
}

//关闭win
function cannel(type,formId){
	if(type =='add' | type =='edit'){
		$('#my_modal_'+type).modal('hide');
		//清空校验
		var validate = $('#'+formId).data('bootstrapValidator').validate();
		validate.resetForm();
	}else{
		$('#my_modal_view').modal('hide');
	}
}

function refresh(){
	getTableData();
}


function setToken(){
	$.ajax({
	    type:'get',
	    url:'${ctx}/sendPage/token?token=true',
	    dataType:'text',
	    success: function(myData){
	    	//console.log(myData);
			$('#addForm_formToken').val(myData);
			$('#editForm_formToken').val(myData);
	  	}
	});	
}



/****  以下是自定义新增方法  ****/
//1.校验规则-定义

function setValidate(id){
	$(id).each(function(){
		$(this).bootstrapValidator({
			feedbackIcons: {
				valid: 'glyphicon glyphicon-ok',
				invalid: 'glyphicon glyphicon-remove',
				validating: 'glyphicon glyphicon-refresh'
			},/** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
			fields:{
				"sysCate.cateNo": {
					validators: {
						notEmpty: {
							message: '分类编号不能为空！'
						},
						regexp: {
							regexp: /^[a-zA-Z0-9]+$/,
							message: '只能是数字英文字母！'
						}
					}
				},
				"sysCate.cateName":{
					validators: {
						notEmpty: {
							message: '分类名称不能为空！'
						}
					}
				}
			}
		});
	});
}

//关闭窗口时清空校验规则
function cleanJiaoyan(formId){
		var validate = $('#'+formId).data('bootstrapValidator').validate();
		validate.resetForm();
}
</script>
    
    
  </div>
  <!-- /.content-wrapper -->
  <!-- foot start -->
	<#include "/common/plateform/foot.ftl">
  <!-- foot start -->
</div>
</body>
</html>




